package com.wframe.project.jnd.wx.wxImpl;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.wframe.project.jnd.rest.util.WebSession;
import com.wframe.project.jnd.util.WebUtils;

public class WeixHelper {

	/**
	 * 获取微信请求过来的openid
	 * @param request
	 * @return
	 */
	public static String getOpenId(HttpServletRequest request){
		String code=request.getParameter("wxcode");
		String openId="";
		try {
       	 if(WebSession.getWxUser(request.getSession(), "")==null){
       		 if(StringUtils.isNotBlank(code)){
                 openId=new WeixInterfaceImpl().getOpenId(code);//获取微信openId
                 if(openId==null)openId="";
       		 }
       	 }else openId=WebSession.getWxUser(request.getSession(), "").getOpenId();
        } catch (Exception e) {
            Logger.getLogger(WeixHelper.class).error(e);
        }
		return openId;
	}
}
